package top.ajun.mall.ware.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * MyBatisPlus 配置
 *
 * @author AJun
 * @date 2020/12/07
 */
@Configuration
@MapperScan("top.ajun.mall.ware.dao")
@EnableTransactionManagement(proxyTargetClass = true)
public class MyBatisConfig {

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 设置请求的页面大于最大页后操作，true: 回到首页, false: 继续请求, 默认为 false
        paginationInterceptor.setOverflow(true);
        // 设置最大单页限制数量，默认 500 条, -1表示不受限制
        paginationInterceptor.setMaxLimit(1000L);
        interceptor.addInnerInterceptor(paginationInterceptor); // 分页插件
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); // 阻止恶意的全表更新删除
        return interceptor;
    }

}
